<template>
  <div class="container">
    <div class="sbgl-nav breadcrumb">
      <img src="static/img/shu.png" alt="">
      <span>个人中心</span>
      <span class="glyphicon glyphicon-chevron-right"></span>
      <span>修改密码</span>
    </div>
    <form class="form-horizontal" id="formEdit" @submit.prevent="submit()">
      <div class="form-group">
          <label for="inputtext1" class="col-sm-2 control-label col-sm-offset-3">原密码：</label>
          <div class="col-sm-4">
            <input type="password" class="form-control" id="inputtext1" v-model="oldPwd">
          </div>
      </div>
      <div class="form-group">
          <label for="inputpassword" class="col-sm-2 control-label col-sm-offset-3">新密码：</label>
          <div class="col-sm-4">
            <input type="password" class="form-control" id="inputtext" v-model="pwd">
          </div>
      </div>
      <div class="form-group">
          <label for="inputpassword2" class="col-sm-2 control-label col-sm-offset-3">确认密码：</label>
          <div class="col-sm-4">
            <input type="password" class="form-control" id="inputpassword2" v-model="rePwd">
          </div>
      </div>
      <p class="lx_btn">
        <button type="submit" class="btn btn-default btn-lg">保存</button>
        <button type="button" onclick="window.history.go(-1)" class="btn btn-default btn-lg">返回</button>
      </p>
    </form>
  </div>
</template>

<script>
  import base from '@/service/Base.vue'
  export default {
    name: 'ChangePwd',
    data: function () {
      return {
        oldPwd: '',
        pwd: '',
        rePwd: ''
      }
    },
    computed: {
      md5Pwd: function () {
        return window.CryptoJS.MD5(this.pwd).toString().toUpperCase()
      }
    },
    methods: {
      submit: function () {
        console.log('submit')
        var data = {
          userid: base.user.userid,
          oldpwd: this.oldpwd,
          pwd: this.md5Pwd
        }
        this.$http.post('/api/hedacmdreq', {method: 'UpdatePwd', data}).then(response => {
          var body = response.data.HedaACK.Body
          if (body.retCode === '0') {
            window.duang.msg(true, body.retMsg)
          }
        })
      }
    }
  }
</script>
